package org.groupg.practice.Compress;

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.atomic.AtomicInteger;

public class ZipFileCounterWithCommonsCompress {

    public static void main(String[] args) {
        String zipFilePath = "path/to/your/zipfile.zip";

        AtomicInteger fileCount = new AtomicInteger(0);

        try (InputStream fis = new FileInputStream(zipFilePath);
             ZipArchiveInputStream zis = new ZipArchiveInputStream(fis)) {

            ZipArchiveEntry entry;
            while ((entry = zis.getNextEntry()) != null) {
                if (!entry.isDirectory()) {
                    fileCount.incrementAndGet();
                }
                // 记得关闭当前条目
                zis.close();
            }

            System.out.println("Number of files in ZIP: " + fileCount.get());

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}